<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录/注册</title>
    <link rel="stylesheet" href="./css/login.css">
</head>
<body>
    <div class="container">
        <div class="form-container">
            <div class="form-toggle">
                <button class="active" onclick="showForm('login')">登录</button>
                <button onclick="showForm('register')">注册</button>
            </div>
            <form id="loginForm" class="form active">
                <input type="text" placeholder="用户名" required>
                <input type="password" placeholder="密码" required>
                <button type="submit">登录</button>
            </form>
            <form id="registerForm" class="form">
                <input type="text" placeholder="用户名" required>
                <input type="email" placeholder="邮箱" required>
                <input type="password" placeholder="密码" required>
                <button type="submit">注册</button>
            </form>
        </div>
    </div>

    <script>
        function showForm(formType) {
            document.querySelectorAll('.form-toggle button').forEach(btn => {
                btn.classList.remove('active');
            });
            document.querySelectorAll('.form').forEach(form => {
                form.classList.remove('active');
            });

            document.querySelector(`[onclick="showForm('${formType}')"]`).classList.add('active');
            document.getElementById(`${formType}Form`).classList.add('active');
        }

        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            const username = this.querySelector('input[type="text"]').value.trim();
            const password = this.querySelector('input[type="password"]').value.trim();
            
            if (username && password) {
                window.location.href = 'main.html';
            } else {
                alert('请输入用户名和密码');
            }
        });
    </script>
</body>
</html>
